import threading
import time

import blog_spider


# 单线程
def single_thread():
    print('single_thread Start')
    for url in blog_spider.urls:
        blog_spider.craw(url)
    print('single_thread End')


# 多线程
def multi_thread():
    print('multi_thread Start')
    threads = []
    for url in blog_spider.urls:
        threads.append(
            threading.Thread(target=blog_spider.craw, args=(url,))
        )

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()
    print('multi_thread End')


if __name__ == '__main__':
    start = time.time()
    single_thread()
    end = time.time()
    print(f'single_thread 用时{end - start}秒')

    start = time.time()
    multi_thread()
    end = time.time()
    print(f'multi_thread 用时{end - start}秒')
